//主模块 定义一些角色 要求state必须是一个函数

//state nuxt要求必须暴露 一个state
export const state=()=>({
    bNav:false,
    bLoading:false
})

//其他角色默认都是对象 也需要暴露
//mutations 导航和loading的突变
export const mutations={
    M_UPDATE_NAV(state,payload){
        state.bNav = payload;
    },
    M_UPDATE_LOADING(state,payload){
        state.bLoading = payload;
    }
}

//actions 
export const actions = {
    nuxtServerInit(store,{app:{$cookies}}){
        // 初始化token到store中
        // console.log("nuxtServerInit",store,context);
        let user = $cookies.get('user')?$cookies.get('user'):{err:2,msg:'未登录'};
        store.commit('user/M_UPDATE_USER',user);
    }
}

export const getters = {
    getNav(state){
        return state.bNav?'显示':'隐藏';
    }
}